<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('用户修改')"/>
</head>
<body>
<form action="" class="layui-form" th:object="${TsysUser}">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label">编号</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" lay-verify="title" name="id"
                               placeholder="请输入标题" th:value="*{id}" type="text">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">原登录密码</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" disabled
                               placeholder="原登录密码" th:value="*{password2}" type="text">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">登录密码</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" id="pwd" lay-verify="password" name="password"
                               placeholder="请输入登录密码" type="password">
                        <img onmouseout="hidePass()"
                             onmouseover="showPass()" src="/static/admin/images/viewPass.png" style=" float: right; width: 20px;"/>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">确认密码</label>
                    <div class="layui-input-block">
                        <input autocomplete="off" class="layui-input" id="pwd2" lay-verify="confirm" name="confirm"
                               placeholder="请输入确认密码" type="password">
                        <img onmouseout="hidePass2()"
                             onmouseover="showPass2()" src="/static/admin/images/viewPass.png" style=" float: right; width: 20px;"/>
                    </div>
                </div>


            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button class="layui-btn layui-btn-normal layui-btn-sm" lay-filter="user-update" lay-submit=""
                    type="submit">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button class="layui-btn layui-btn-primary layui-btn-sm" type="reset">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<th:block th:include="include :: footer"/>
<script>
    layui.use(['form', 'admin', 'jquery', 'layer', 'popup'], function () {
        var form = layui.form;
        var admin = layui.admin;
        var $ = layui.jquery;
        var layer = layui.layer;
        var popup = layui.popup;
        admin.render();
        var MODULE_PATH = rootPath + "/UserController";
        //名称验证
        form.verify({
            confirm: function (value) {
                var pwd = $("input[name='password']").val();
                var confirm = $("input[name='confirm']").val();
                if (pwd != confirm) {
                    return '两次密码输入不一致';
                }
            }
        });

        form.on('submit(user-update)', function (data) {
            var msg = checkingPassword(data.field.password);
            if (msg != 'success') {
                layer.msg(msg, {icon: 2, time: 3000});
                return false;
            }

            $.ajax({
                url: MODULE_PATH + '/editPwd2',
                data: data.field,
                dataType: 'json',
                contentType: 'application/x-www-form-urlencoded',
                type: 'post',
                success: function (result) {
                    if (result.code == 200) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            var loading = layer.load();
                            $.ajax({
                                url: rootPath + '/admin/Loginout',
                                dataType: 'json',
                                type: 'get',
                                success: function (result) {
                                    if (result.code == 200) {
                                        popup.success(result.msg, function () {
                                        });
                                        location.href = rootPath + "/";
                                        return true;
                                    }
                                }
                            })
                            return true;
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });

        window.checkingPassword = function (str) {
            var msg;
            var rC = {
                lW: '[a-z]',
                uW: '[A-Z]',
                nW: '[0-9]',
                sW: '[\\u0020-\\u002F\\u003A-\\u0040\\u005B-\\u0060\\u007B-\\u007E]'
            };

            function Reg(str, rStr) {
                var reg = new RegExp(rStr);
                if (reg.test(str)) return true;
                else return false;
            }

            if (str.length < 6) {
                msg = "密码长度需大于等于6位";
                return msg;
            } else {
                var tR = {
                    l: Reg(str, rC.lW),
                    u: Reg(str, rC.uW),
                    n: Reg(str, rC.nW),
                    s: Reg(str, rC.sW)
                };
                if ((tR.l && tR.u && tR.n) || (tR.l && tR.u && tR.s) || (tR.s && tR.u && tR.n) || (tR.s && tR.l && tR.n)) {
                    // document.title = '密码符合要求';
                    msg = 'success';
                    return msg;
                } else {
                    // document.title = '您的密码必须含有“小写字母”、“大写字母”、“数字”、“特殊符号”中的任意三种';
                    msg = '密码需由“小写字母”、“大写字母”、“数字”、“特殊符号”中的任意三种组合而成';
                    return msg;
                }
            }
        }

        window.showPass = function () {
            $('#pwd').prop('type', 'text');

        }
        window.hidePass = function () {
            $('#pwd').prop('type', 'password');
        }
        window.showPass2 = function () {
            $('#pwd2').prop('type', 'text');

        }
        window.hidePass2 = function () {
            $('#pwd2').prop('type', 'password');
        }
    })
</script>
<script>
</script>
</body>
</html>